home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / dev / debug / Wipeout.lha / source / main.c < prev    next >
C/C++ Source or Header  |  1998-04-16  |  18KB  |  839 lines

  1. /*
  2.  * $Id: main.c 1.17 1998/04/16 10:26:48 olsen Exp olsen $
  3.  *
  4.  * :ts=4
  5.  *
  6.  * Wipeout -- Traces and munges memory and detects memory trashing
  7.  *
  8.  * Written by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
  9.  * Public Domain
  10.  */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "global.h"
  14. #endif    /* _GLOBAL_H */
  15.  
  16. /******************************************************************************/
  17.  
  18. #include "Wipeout_rev.h"
  19.  
  20. /******************************************************************************/
  21.  
  22. const STRPTR VersTag = VERSTAG;
  23.  
  24. /******************************************************************************/
  25.  
  26. STATIC const STRPTR Separator = "======================================="
  27.                                 "=======================================";
  28.  
  29. /******************************************************************************/
  30.  
  31. STATIC struct WipeoutSemaphore *    WipeoutSemaphore;
  32. STATIC BOOL                            WipeoutSemaphoreCreated;
  33.  
  34. /******************************************************************************/
  35.  
  36. STATIC BOOL ShowBannerMessage = TRUE;
  37.  
  38. /******************************************************************************/
  39.  
  40. STATIC BYTE TimerSignal;
  41.  
  42. /******************************************************************************/
  43.  
  44. STATIC LONG
  45. SendWipeoutCmd(LONG command,APTR parameter)
  46. {
  47.     WipeoutSemaphore->ws_Client        = FindTask(NULL);
  48.     WipeoutSemaphore->ws_Command    = command;
  49.     WipeoutSemaphore->ws_Parameter    = parameter;
  50.     WipeoutSemaphore->ws_Error        = OK;
  51.  
  52.     /* wake up the wipeout semaphore owner and exchange
  53.      * data or information with it
  54.      */
  55.     SetSignal(0,SIG_Handshake);
  56.     Signal(WipeoutSemaphore->ws_WipeoutTask,WipeoutSemaphore->ws_WakeupMask);
  57.     Wait(SIG_Handshake);
  58.  
  59.     return(WipeoutSemaphore->ws_Error);
  60. }
  61.  
  62. /******************************************************************************/
  63.  
  64. STATIC VOID
  65. Cleanup(VOID)
  66. {
  67.     /* shut down the timer */
  68.     DeleteTimer();
  69.  
  70.     if(WipeoutSemaphore != NULL)
  71.     {
  72.         if(WipeoutSemaphoreCreated)
  73.         {
  74.             /* remove the semaphore from the public list */
  75.             RemSemaphore((struct SignalSemaphore *)WipeoutSemaphore);
  76.  
  77.             /* gain ownership over it */
  78.             ObtainSemaphore((struct SignalSemaphore *)WipeoutSemaphore);
  79.             ReleaseSemaphore((struct SignalSemaphore *)WipeoutSemaphore);
  80.  
  81.             /* and release it */
  82.             FreeMem(WipeoutSemaphore,sizeof(*WipeoutSemaphore));
  83.         }
  84.         else
  85.         {
  86.             /* drop the ownership */
  87.             ReleaseSemaphore((struct SignalSemaphore *)WipeoutSemaphore);
  88.         }
  89.  
  90.         WipeoutSemaphore = NULL;
  91.     }
  92.  
  93.     /* clear the allocation filters */
  94.     ClearFilterList();
  95.  
  96.     /* get rid of the wakeup signal */
  97.     if(WakeupSignal != -1)
  98.     {
  99.         FreeSignal(WakeupSignal);
  100.         WakeupSignal = -1;
  101.     }
  102.  
  103.     /* close utility.library, if this is necessary */
  104.     #if !defined(__SASC) || defined(_M68020)
  105.     {
  106.         if(UtilityBase != NULL)
  107.         {
  108.             CloseLibrary(UtilityBase);
  109.             UtilityBase = NULL;
  110.         }
  111.     }
  112.     #endif
  113. }
  114.  
  115. STATIC BOOL
  116. Setup(VOID)
  117. {
  118.     struct WipeoutSemaphore * ws = NULL;
  119.     LONG error = OK;
  120.     int i;
  121.  
  122.     WakeupSignal = -1;
  123.     InitFilterList();
  124.  
  125.     /* determine the program name */
  126.     StrcpyN(sizeof(ProgramName),ProgramName,VERS);
  127.  
  128.     for(i = strlen(ProgramName) - 1 ; i >= 0 ; i--)
  129.     {
  130.         if(ProgramName[i] == ' ')
  131.         {
  132.             ProgramName[i] = '\0';
  133.             break;
  134.         }
  135.     }
  136.  
  137.     /* fill in the name and the version number */
  138.     SPrintfN(sizeof(ProgramNameAndVersion),ProgramNameAndVersion,"%s (%s)",VERS,DATE);
  139.  
  140.     /* Kickstart 2.04 or higher required */
  141.     if(SysBase->LibNode.lib_Version < 37)
  142.     {
  143.         const STRPTR message = "This program requires Kickstart 2.04 or better.\n";
  144.  
  145.         Write(Output(),message,strlen(message));
  146.         return(FAILURE);
  147.     }
  148.  
  149.     /* open utility.library, if this is necessary */
  150.     #if !defined(__SASC) || defined(_M68020)
  151.     {
  152.         UtilityBase = OpenLibrary("utility.library",37);
  153.         if(UtilityBase == NULL)
  154.         {
  155.             Printf("%s: Could not open utility.library V37.\n",ProgramName);
  156.             return(FAILURE);
  157.         }
  158.     }
  159.     #endif
  160.  
  161.     /* allocate the timer data */
  162.     TimerSignal = CreateTimer();
  163.     if(TimerSignal == -1)
  164.     {
  165.         Printf("%s: Could not create timer.\n",ProgramName);
  166.         return(FAILURE);
  167.     }
  168.  
  169.     /* allocate the wakeup signal */
  170.     WakeupSignal = AllocSignal(-1);
  171.     if(WakeupSignal == -1)
  172.     {
  173.         Printf("%s: Could not allocate wakeup signal.\n",ProgramName);
  174.         return(FAILURE);
  175.     }
  176.  
  177.     Forbid();
  178.  
  179.     /* try to find the global wipeout semaphore */
  180.     WipeoutSemaphore = (struct WipeoutSemaphore *)FindSemaphore(WIPEOUTSEMAPHORENAME);
  181.     if(WipeoutSemaphore == NULL)
  182.     {
  183.         /* it does not exist yet; create it */
  184.         WipeoutSemaphore = AllocMem(sizeof(*WipeoutSemaphore),MEMF_ANY|MEMF_PUBLIC|MEMF_CLEAR);
  185.         if(WipeoutSemaphore != NULL)
  186.         {
  187.             WipeoutSemaphoreCreated = TRUE;
  188.  
  189.             ws = WipeoutSemaphore;
  190.  
  191.             /* fill in name and priority; AddSemaphore() will take
  192.              * care of the rest
  193.               */
  194.             ws->ws_SignalSemaphore.ss_Link.ln_Name    = ws->ws_SemaphoreName;
  195.             ws->ws_SignalSemaphore.ss_Link.ln_Pri    = 1;
  196.  
  197.             strcpy(ws->ws_SemaphoreName,WIPEOUTSEMAPHORENAME);
  198.  
  199.             /* for compatibility checking, if the semaphore
  200.              * needs to grow
  201.              */
  202.             ws->ws_Version = WIPEOUTSEMAPHOREVERSION;
  203.  
  204.             /* fill in references to changeable parameters */
  205.             ws->ws_IsActive            = &IsActive;
  206.             ws->ws_ShowFail            = &ShowFail;
  207.             ws->ws_WaitAfterHit        = &WaitAfterHit;
  208.             ws->ws_NameTag            = &NameTag;
  209.             ws->ws_NameTag            = &NameTag;
  210.             ws->ws_CheckConsistency    = &CheckConsistency;
  211.             ws->ws_ARegCheck        = &ARegCheck;
  212.             ws->ws_DRegCheck        = &DRegCheck;
  213.             ws->ws_StackCheck        = &StackCheck;
  214.             ws->ws_StackLines        = &StackLines;
  215.             ws->ws_CheckDelay        = &CheckDelay;
  216.             ws->ws_WipeoutTask        = FindTask(NULL);
  217.             ws->ws_WakeupMask        = (1UL << WakeupSignal);
  218.  
  219.             /* and finally make the semaphore public */
  220.             AddSemaphore((struct SignalSemaphore *)ws);
  221.         }
  222.         else
  223.         {
  224.             error = ERROR_NO_FREE_STORE;
  225.         }
  226.     }
  227.     else
  228.     {
  229.         ws = WipeoutSemaphore;
  230.  
  231.         /* obtain ownership of the semaphore */
  232.         ObtainSemaphore((struct SignalSemaphore *)ws);
  233.     }
  234.  
  235.     Permit();
  236.  
  237.     if(error == OK)
  238.     {
  239.         struct RDArgs * rda;
  240.  
  241.         /* these are the command line parameters, later
  242.          * filled in by ReadArgs() below
  243.          */
  244.         struct
  245.         {
  246.             /* the following options control the startup defaults
  247.              * and cannot be changed by subsequent invocations
  248.              * of Wipeout
  249.              */
  250.             NUMBER    PreSize;
  251.             NUMBER    PostSize;
  252.             KEY        FillChar;
  253.             SWITCH    Parallel;
  254.             SWITCH    NoBanner;
  255.  
  256.             /* the following options can be changed at run-time */
  257.             SWITCH    Remunge;
  258.             SWITCH    Check;
  259.             SWITCH    Mark;
  260.             SWITCH    Unmark;
  261.             SWITCH    ShowUnmarked;
  262.             KEY        Name;
  263.             SWITCH    NameTag;
  264.             SWITCH    NoNameTag;
  265.             SWITCH    Active;
  266.             SWITCH    Inactive;
  267.             SWITCH    Wait;
  268.             SWITCH    NoWait;
  269.             SWITCH    ConsistenceCheck;
  270.             SWITCH    NoConsistenceCheck;
  271.             SWITCH    Reuse;
  272.             SWITCH    NoReuse;
  273.             SWITCH    ShowFail;
  274.             SWITCH    NoShowFail;
  275.             SWITCH    ARegCheck;
  276.             SWITCH    NoARegCheck;
  277.             SWITCH    DRegCheck;
  278.             SWITCH    NoDRegCheck;
  279.             SWITCH    StackCheck;
  280.             SWITCH    NoStackCheck;
  281.             NUMBER    StackLines;
  282.             NUMBER    CheckDelay;
  283.         } params;
  284.     
  285.         /* this is the command template, as required by ReadArgs() below;
  286.          * its contents must match the "params" data structure above
  287.          */
  288.         const STRPTR cmdTemplate =
  289.             "PRESIZE/K/N,"
  290.             "POSTSIZE/K/N,"
  291.             "FILLCHAR/K,"
  292.             "PARALLEL/S,"
  293.             "NOBANNER/S,"
  294.             "REMUNGE=REMUNG/S,"
  295.             "CHECK/S,"
  296.             "MARK/S,"
  297.             "UNMARK/S,"
  298.             "SHOWUNMARKED/S,"
  299.             "NAME=TASK/K,"
  300.             "NAMETAG/S,"
  301.             "NONAMETAG/S,"
  302.             "ACTIVE=ENABLE/S,"
  303.             "INACTIVE=DISABLE/S,"
  304.             "WAIT/S,"
  305.             "NOWAIT/S,"
  306.             "CONSISTENCECHECK/S,"
  307.             "NOCONSISTENCECHECK/S,"
  308.             "REUSE/S,"
  309.             "NOREUSE/S,"
  310.             "SHOWFAIL/S,"
  311.             "NOSHOWFAIL/S,"
  312.             "AREGCHECK/S,"
  313.             "NOAREGCHECK/S,"
  314.             "DREGCHECK/S,"
  315.             "NODREGCHECK/S,"
  316.             "STACKCHECK/S,"
  317.             "NOSTACKCHECK/S,"
  318.             "STACKLINES/K/N,"
  319.             "CHECKDELAY/K/N";
  320.  
  321.         memset(¶ms,0,sizeof(params));
  322.  
  323.         /* read the command line parameters */
  324.         rda = ReadArgs((STRPTR)cmdTemplate,(LONG *)¶ms,NULL);
  325.         if(rda != NULL)
  326.         {
  327.             /* establish defaults */
  328.             PreWallSize            = 32;
  329.             PostWallSize        = 32;
  330.             IsActive            = TRUE;
  331.             CheckConsistency    = TRUE;
  332.             StackLines            = 2;
  333.  
  334.             /* trigger a memory check? */
  335.             if(params.Check)
  336.             {
  337.                 Signal(ws->ws_WipeoutTask,SIG_Check);
  338.             }
  339.  
  340.             /* disable wipeout? */
  341.             if(params.Inactive)
  342.             {
  343.                 Signal(ws->ws_WipeoutTask,SIG_Disable);
  344.             }
  345.  
  346.             /* enable wipeout? */
  347.             if(params.Active)
  348.             {
  349.                 Signal(ws->ws_WipeoutTask,SIG_Enable);
  350.             }
  351.  
  352.             /* remunge memory? */
  353.             if(params.Remunge)
  354.             {
  355.                 /* tell the semaphore owner to munge the memory */
  356.                 if(NOT WipeoutSemaphoreCreated)
  357.                 {
  358.                     SendWipeoutCmd(WIPEOUTCMD_Remunge,NULL);
  359.                 }
  360.             }
  361.  
  362.             /* mark all allocations? */
  363.             if(params.Mark)
  364.             {
  365.                 /* tell the semaphore owner to mark the allocations */
  366.                 if(NOT WipeoutSemaphoreCreated)
  367.                 {
  368.                     SendWipeoutCmd(WIPEOUTCMD_Mark,NULL);
  369.                 }
  370.             }
  371.  
  372.             /* clear all allocation marks? */
  373.             if(params.Unmark)
  374.             {
  375.                 /* tell the semaphore owner to clear the marks */
  376.                 if(NOT WipeoutSemaphoreCreated)
  377.                 {
  378.                     SendWipeoutCmd(WIPEOUTCMD_Unmark,NULL);
  379.                 }
  380.             }
  381.  
  382.             /* show all unmarked allocations? */
  383.             if(params.ShowUnmarked)
  384.             {
  385.                 /* tell the semaphore owner to clear the marks */
  386.                 if(NOT WipeoutSemaphoreCreated)
  387.                 {
  388.                     SendWipeoutCmd(WIPEOUTCMD_ShowUnmarked,NULL);
  389.                 }
  390.             }
  391.  
  392.             /* put together a list of tasks to filter out
  393.              * when making memory allocations?
  394.              */
  395.             if(params.Name != NULL)
  396.             {
  397.                 if(WipeoutSemaphoreCreated)
  398.                 {
  399.                     /* we created the semaphore, so we can
  400.                      * fill in the filter lists all by
  401.                      * ourselves.
  402.                      */
  403.                     if(CANNOT UpdateFilter(params.Name))
  404.                         error = ERROR_NO_FREE_STORE;
  405.                 }
  406.                 else
  407.                 {
  408.                     /* we did not create the semaphore,
  409.                      * so we will have to tell the semaphore
  410.                      * owner to update the filter lists.
  411.                      */
  412.                     error = SendWipeoutCmd(WIPEOUTCMD_UpdateFilterList,params.Name);
  413.                 }
  414.             }
  415.  
  416.             /* set the pre-wall allocation size */
  417.             if(params.PreSize != NULL)
  418.             {
  419.                 LONG value;
  420.  
  421.                 value = ((*params.PreSize) + 3) & ~3;
  422.                 if(value < 4)
  423.                     value = 4;
  424.                 else if (value > 65535)
  425.                     value = 65535;
  426.  
  427.                 PreWallSize = value;
  428.             }
  429.  
  430.             /* set the post-wall allocation size */
  431.             if(params.PostSize != NULL)
  432.             {
  433.                 LONG value;
  434.  
  435.                 value = ((*params.PostSize) + 3) & ~3;
  436.                 if(value < 4)
  437.                     value = 4;
  438.                 else if (value > 65535)
  439.                     value = 65535;
  440.  
  441.                 PostWallSize = value;
  442.             }
  443.  
  444.             if(params.ARegCheck)
  445.             {
  446.                 (*ws->ws_ARegCheck) = TRUE;
  447.             }
  448.  
  449.             if(params.NoARegCheck)
  450.             {
  451.                 (*ws->ws_ARegCheck) = FALSE;
  452.             }
  453.  
  454.             if(params.DRegCheck)
  455.             {
  456.                 (*ws->ws_DRegCheck) = TRUE;
  457.             }
  458.  
  459.             if(params.NoDRegCheck)
  460.             {
  461.                 (*ws->ws_DRegCheck) = FALSE;
  462.             }
  463.  
  464.             if(params.Wait)
  465.             {
  466.                 (*ws->ws_WaitAfterHit) = TRUE;
  467.             }
  468.  
  469.             if(params.NoWait)
  470.             {
  471.                 (*ws->ws_WaitAfterHit) = FALSE;
  472.             }
  473.  
  474.             if(params.ConsistenceCheck)
  475.             {
  476.                 (*ws->ws_CheckConsistency) = TRUE;
  477.             }
  478.  
  479.             if(params.NoConsistenceCheck)
  480.             {
  481.                 (*ws->ws_CheckConsistency) = FALSE;
  482.             }
  483.  
  484.             if(params.NameTag)
  485.             {
  486.                 (*ws->ws_NameTag) = TRUE;
  487.             }
  488.  
  489.             if(params.NoNameTag)
  490.             {
  491.                 (*ws->ws_NameTag) = FALSE;
  492.             }
  493.  
  494.             if(params.Reuse)
  495.             {
  496.                 (*ws->ws_NoReuse) = FALSE;
  497.             }
  498.  
  499.             if(params.NoReuse)
  500.             {
  501.                 (*ws->ws_NoReuse) = TRUE;
  502.             }
  503.  
  504.             if(params.StackCheck)
  505.             {
  506.                 (*ws->ws_StackCheck) = TRUE;
  507.             }
  508.  
  509.             if(params.NoStackCheck)
  510.             {
  511.                 (*ws->ws_StackCheck) = FALSE;
  512.             }
  513.  
  514.             if(params.StackLines != NULL)
  515.             {
  516.                 LONG value;
  517.  
  518.                 value = (*params.StackLines);
  519.                 if(value < 1)
  520.                     value = 1;
  521.  
  522.                 (*ws->ws_StackLines) = value;
  523.             }
  524.  
  525.             if(params.ShowFail)
  526.             {
  527.                 (*ws->ws_ShowFail) = TRUE;
  528.             }
  529.  
  530.             if(params.NoShowFail)
  531.             {
  532.                 (*ws->ws_ShowFail) = FALSE;
  533.             }
  534.  
  535.             /* do not show the banner message? */
  536.             if(params.NoBanner)
  537.             {
  538.                 ShowBannerMessage = FALSE;
  539.             }
  540.  
  541.             /* enable parallel port output? */
  542.             if(params.Parallel)
  543.             {
  544.                 ChooseParallelOutput();
  545.             }
  546.  
  547.             /* use a special fill character? */
  548.             if(params.FillChar != NULL)
  549.             {
  550.                 LONG number;
  551.  
  552.                 /* this can either be a decimal or a
  553.                  * hexadecimal number; the latter is
  554.                  * indicated by a preceding "$" or "0x"
  555.                  */
  556.                 if(DecodeNumber(params.FillChar,&number))
  557.                 {
  558.                     if(0 <= number && number <= 255)
  559.                     {
  560.                         SetFillChar(number);
  561.                     }
  562.                     else
  563.                     {
  564.                         error = ERROR_BAD_NUMBER;
  565.                     }
  566.                 }
  567.                 else
  568.                 {
  569.                     error = ERROR_BAD_NUMBER;
  570.                 }
  571.             }
  572.  
  573.             /* set or update the automatic check delay? */
  574.             if(params.CheckDelay != NULL)
  575.             {
  576.                 LONG value;
  577.  
  578.                 value = (*params.CheckDelay);
  579.                 if(value < 0)
  580.                     value = 0;
  581.  
  582.                 CheckDelay = value;
  583.  
  584.                 /* notify the semaphore owner of the
  585.                  * new check delay; this will automatically
  586.                  * trigger a new memory check
  587.                  */
  588.                 if(NOT WipeoutSemaphoreCreated)
  589.                 {
  590.                     error = SendWipeoutCmd(WIPEOUTCMD_NewCheckDelay,(APTR)CheckDelay);
  591.                 }
  592.             }
  593.  
  594.             FreeArgs(rda);
  595.         }
  596.         else
  597.         {
  598.             error = IoErr();
  599.         }
  600.     }
  601.  
  602.     if(error == OK)
  603.     {
  604.         /* set up the tracking lists */
  605.         SetupAllocationList();
  606.         SetupPoolList();
  607.  
  608.         return(SUCCESS);
  609.     }
  610.     else
  611.     {
  612.         PrintFault(error,ProgramName);
  613.  
  614.         return(FAILURE);
  615.     }
  616. }
  617.  
  618. /******************************************************************************/
  619.  
  620. int
  621. main(
  622.     int        argc,
  623.     char **    argv)
  624. {
  625.     int result = RETURN_FAIL;
  626.  
  627.     /* set up all the data we need */
  628.     if(Setup())
  629.     {
  630.         result = RETURN_OK;
  631.  
  632.         /* are we the owner of the semaphore? if
  633.          * so, do something useful
  634.          */
  635.         if(WipeoutSemaphoreCreated)
  636.         {
  637.             ULONG signalsReceived;
  638.             ULONG sigWakeup = (1UL<<WakeupSignal);
  639.             ULONG sigTimer = (1UL<<TimerSignal);
  640.     
  641.             /* munge all free memory */
  642.             if(ShowBannerMessage)
  643.             {
  644.                 DPrintf("%s -- Traces and munges memory and detects memory trashing\n",ProgramName);
  645.                 DPrintf("Written by Olaf `Olsen' Barthel <olsen@sourcery.han.de>\n");
  646.                 DPrintf("Public Domain\n\n");
  647.  
  648.                 DPrintf("Munging memory... ");
  649.             }
  650.  
  651.             BeginMemMung();
  652.  
  653.             if(ShowBannerMessage)
  654.             {
  655.                 struct timeval tv;
  656.  
  657.                 Forbid();
  658.                 GetSysTime(&tv);
  659.                 ConvertTimeAndDate(&tv,GlobalDateBuffer,GlobalTimeBuffer);
  660.                 DPrintf("done (%s%s).\n",GlobalDateBuffer,GlobalTimeBuffer);
  661.                 Permit();
  662.             }
  663.     
  664.             /* plant the monitoring patches */
  665.             InstallPatches();
  666.  
  667.             /* if we are to check the memory list periodically,
  668.              * start the timer now
  669.              */
  670.             if(CheckDelay > 0)
  671.             {
  672.                 StartTimer(CheckDelay / 10,(CheckDelay % 10) * (MILLION / 10));
  673.             }
  674.     
  675.             while(TRUE)
  676.             {
  677.                 /* wait for something to happen */
  678.                 signalsReceived = Wait(SIG_Check | SIG_Disable | SIG_Enable | sigWakeup | sigTimer);
  679.  
  680.                 /* received a command? */
  681.                 if(FLAG_IS_SET(signalsReceived,sigWakeup))
  682.                 {
  683.                     APTR parameter = WipeoutSemaphore->ws_Parameter;
  684.                     LONG error = OK;
  685.  
  686.                     /* what are we to do now? */
  687.                     switch(WipeoutSemaphore->ws_Command)
  688.                     {
  689.                         /* update the filter list? */
  690.                         case WIPEOUTCMD_UpdateFilterList:
  691.  
  692.                             if(CANNOT UpdateFilter((STRPTR)parameter))
  693.                                 error = ERROR_NO_FREE_STORE;
  694.  
  695.                             break;
  696.  
  697.                         /* change the check timer delay? */
  698.                         case WIPEOUTCMD_NewCheckDelay:
  699.  
  700.                             CheckDelay = (LONG)parameter;
  701.  
  702.                             /* re-check the check timer delay */
  703.                             signalsReceived |= sigTimer;
  704.                             break;
  705.  
  706.                         /* remunge unallocated memory? */
  707.                         case WIPEOUTCMD_Remunge:
  708.  
  709.                             DPrintf("Remunging memory... ");
  710.                             BeginMemMung();
  711.                             DPrintf("done.\n");
  712.  
  713.                             break;
  714.  
  715.                         /* mark all "current" memory allocations? */
  716.                         case WIPEOUTCMD_Mark:
  717.  
  718.                             DPrintf("Marking memory... ");
  719.                             ChangeMemoryMarks(TRUE);
  720.                             ChangePuddleMarks(TRUE);
  721.                             DPrintf("done.\n");
  722.                             break;
  723.  
  724.                         /* clear all memory marks? */
  725.                         case WIPEOUTCMD_Unmark:
  726.  
  727.                             DPrintf("Clearing memory marks... ");
  728.                             ChangeMemoryMarks(FALSE);
  729.                             ChangePuddleMarks(FALSE);
  730.                             DPrintf("done.\n");
  731.                             break;
  732.  
  733.                         /* show all memory marks? */
  734.                         case WIPEOUTCMD_ShowUnmarked:
  735.  
  736.                             DPrintf("%s\nShowing all unmarked memory allocations\n",Separator);
  737.                             ShowUnmarkedMemory();
  738.                             ShowUnmarkedPools();
  739.                             DPrintf("%s\n\n",Separator);
  740.                             break;
  741.                     }
  742.     
  743.                     /* let the client task go */
  744.                     WipeoutSemaphore->ws_Error = error;
  745.                     Signal(WipeoutSemaphore->ws_Client,SIG_Handshake);
  746.                 }
  747.     
  748.                 /* start or stop the timer, depending on the
  749.                  * check delay length
  750.                  */
  751.                 if(FLAG_IS_SET(signalsReceived,sigTimer))
  752.                 {
  753.                     if(CheckDelay > 0)
  754.                     {
  755.                         StartTimer(CheckDelay / 10,(CheckDelay % 10) * (MILLION / 10));
  756.  
  757.                         signalsReceived |= SIG_Check;
  758.                     }
  759.                     else
  760.                     {
  761.                         StopTimer();
  762.                     }
  763.                 }
  764.  
  765.                 /* check all memory allocations */
  766.                 if(FLAG_IS_SET(signalsReceived,SIG_Check))
  767.                 {
  768.                     struct timeval tv;
  769.  
  770.                     Forbid();
  771.  
  772.                     GetSysTime(&tv);
  773.                     ConvertTimeAndDate(&tv,GlobalDateBuffer,GlobalTimeBuffer);
  774.  
  775.                     DPrintf("%s\nChecking all memory allocations (%s%s)\n%s\n",
  776.                         Separator,GlobalDateBuffer,GlobalTimeBuffer,Separator);
  777.  
  778.                     CheckAllocatedMemory();
  779.                     CheckPools();
  780.                     CheckFilter();
  781.  
  782.                     DPrintf("%s\n\n",Separator);
  783.  
  784.                     Permit();
  785.                 }
  786.     
  787.                 /* stop monitoring memory allocations */
  788.                 if(FLAG_IS_SET(signalsReceived,SIG_Disable))
  789.                 {
  790.                     if(IsActive)
  791.                     {
  792.                         struct timeval tv;
  793.     
  794.                         Forbid();
  795.     
  796.                         GetSysTime(&tv);
  797.                         ConvertTimeAndDate(&tv,GlobalDateBuffer,GlobalTimeBuffer);
  798.     
  799.                         DPrintf("%s\n%s deactivated (%s%s)\n%s\n",
  800.                             Separator,ProgramName,GlobalDateBuffer,GlobalTimeBuffer,Separator);
  801.     
  802.                         IsActive = FALSE;
  803.     
  804.                         Permit();
  805.                     }
  806.                 }
  807.     
  808.                 /* restart monitoring memory allocations */
  809.                 if(FLAG_IS_SET(signalsReceived,SIG_Enable))
  810.                 {
  811.                     if(NOT IsActive)
  812.                     {
  813.                         struct timeval tv;
  814.  
  815.                         Forbid();
  816.  
  817.                         GetSysTime(&tv);
  818.                         ConvertTimeAndDate(&tv,GlobalDateBuffer,GlobalTimeBuffer);
  819.  
  820.                         DPrintf("%s\n%s activated (%s%s)\n%s\n",
  821.                             Separator,ProgramName,GlobalDateBuffer,GlobalTimeBuffer,Separator);
  822.  
  823.                         IsActive = TRUE;
  824.  
  825.                         Permit();
  826.                     }
  827.                 }
  828.             }
  829.         }
  830.     }
  831.  
  832.     /* note that we never arrive here if we are the owner
  833.      * of the wipeout semaphore
  834.      */
  835.     Cleanup();
  836.  
  837.     return(result);
  838. }
  839.